﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DLLCOM;

namespace DLLCOM
{
    /// <summary>
    /// DLL_noDelegate.xaml 的交互逻辑
    /// </summary>
    public partial class DLL_Delegate : Page
    {
        public DLL_Delegate()
        {
            InitializeComponent();
        }

        private void doAdd_Click(object sender, RoutedEventArgs e)
        {
            int res = DLL_CS.Add(int.Parse(add1.Text), int.Parse(add2.Text));
            add_res.Text = String.Concat(res);
        }

        private void doMulti_Click(object sender, RoutedEventArgs e)
        {
            int res = DLL_CS.Multi(int.Parse(multi1.Text), int.Parse(multi2.Text));
            multi_res.Text = String.Concat(res);
        }

        private void doFra_Click(object sender, RoutedEventArgs e)
        {
            int res = DLL_CS.Factorial(int.Parse(fra1.Text));
            fra_res.Text = String.Concat(res);
        }

        private void ShowFunc_Click(object sender, RoutedEventArgs e)
        {
            FuncName.Text = "";
            Assembly assembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "DLL_Delegate.dll");
            Type type = assembly.GetType("DLLCOM.DLL_CS");

            System.Reflection.MethodInfo[] ms = type.GetMethods();
            foreach (System.Reflection.MethodInfo methodInfo in ms)
            {

                string method = "";
                method += methodInfo.ReturnType.Name;
                method += " " + methodInfo.Name;
                System.Reflection.ParameterInfo[] ps = methodInfo.GetParameters();
                int count = 0;
                method += "(";
                foreach (System.Reflection.ParameterInfo parameter in ps)
                {
                    if (count == 0)
                        method += parameter.ParameterType.Name + " " + parameter.Name;
                    else
                        method += "," + parameter.ParameterType.Name + " " + parameter.Name;

                    count += 1;
                }
                method += ")";
                FuncName.Text += (method + "\n");
            }
        }
    }
}
